package com.link2room.rodimus.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.threadlocal.BaseThreadLocal;
import com.link2room.rodimus.dto.param.api.MallAddressApiParamDto;
import com.link2room.rodimus.dto.param.api.MallGoodsApiParamDto;
import com.link2room.rodimus.dto.param.api.MallOrderApiParamDto;
import com.link2room.rodimus.dto.param.api.MallOrderPrepayParamDto;
import com.link2room.rodimus.facade.IMallApiFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by VegetaKo on 2017/1/3.
 */
@Api(tags = "商城相关")
@RestController
@RequestMapping("/api/MallNew/Mall")
public class MallApiControllerRemoveTicket {
    @Resource
    IMallApiFacadeService mallApiFacadeService;

    @RequestMapping(value="/GoodCategorys",method = RequestMethod.GET)
    public BaseResultDto listGoodCategorys() throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        resDto.setQueryResult(mallApiFacadeService.getGoodCategorysList());
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Goods",method = RequestMethod.GET)
    public BaseResultDto listGoods(
            @RequestParam (value = "goodCategory" ,required = false) String goodCategory,
            @Deprecated @RequestParam (value = "sort" ,required = false) String sort,
            @RequestParam(value = "orderBy",required = false)String orderBy ,
            @RequestParam(value = "isAsc",required = false)String isAsc,
            @RequestParam(value = "isHot",required = false)String isHot) throws Exception {
        MallGoodsApiParamDto mallGoodsApiParamDto = new MallGoodsApiParamDto();
        mallGoodsApiParamDto.setIsAsc(isAsc);
        mallGoodsApiParamDto.setIsHot(isHot);
        mallGoodsApiParamDto.setOrderBy(orderBy);
        mallGoodsApiParamDto.setGoodCategory(goodCategory );
        mallGoodsApiParamDto.setSort(sort );
        BaseResultDto resDto = new BaseResultDto();
        resDto.setQueryResult( mallApiFacadeService.getGoodsList( mallGoodsApiParamDto) );
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Goods/{id}",method = RequestMethod.GET)
    public BaseResultDto getGood(
            @PathVariable Long id) throws Exception {
        MallGoodsApiParamDto mallGoodsApiParamDto = new MallGoodsApiParamDto();
        mallGoodsApiParamDto.setId(id);
        mallGoodsApiParamDto.setOptId( BaseThreadLocal.getOptId());
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo( mallApiFacadeService.getGoodById( mallGoodsApiParamDto));
        resDto.setOptId(BaseThreadLocal.getOptId() );
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Good",method = RequestMethod.GET)
    public BaseResultDto getGoodByCode(
            @RequestParam(name = "goodCode") String goodCode) throws Exception {
        MallGoodsApiParamDto mallGoodsApiParamDto = new MallGoodsApiParamDto();
        mallGoodsApiParamDto.setGoodCode(goodCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo( mallApiFacadeService.getGoodByCode( mallGoodsApiParamDto));
        resDto.setOptId(BaseThreadLocal.getOptId() );
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Orders",method = RequestMethod.GET)
    public BaseResultDto lisetOrders(
            @RequestParam(name = "productCode",required = false)String productCode,
            @RequestParam(name = "orderType",required = false)String orderType
    ) throws Exception {
        MallOrderApiParamDto mallOrderApiParamDto = new MallOrderApiParamDto();
        mallOrderApiParamDto.setOrderType(orderType);
        mallOrderApiParamDto.setProductCode(productCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setQueryResult( mallApiFacadeService.getOrders(mallOrderApiParamDto ));
        resDto.setResultCode(0);
        return resDto;
    }
    @RequestMapping(value="/Members/Orders",method = RequestMethod.POST)
    public BaseResultDto newOrder(
            @RequestBody MallOrderApiParamDto mallOrderApiParamDto
    ) throws Exception {
        //MallOrderApiParamDto mallOrderApiParamDto = new MallOrderApiParamDto();
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo( mallApiFacadeService.newOrder(mallOrderApiParamDto ));
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Orders/{id}",method = RequestMethod.GET)
    public BaseResultDto getOrder(
            @PathVariable Long id

    ) throws Exception {
        MallOrderApiParamDto mallOrderApiParamDto = new MallOrderApiParamDto();
        mallOrderApiParamDto.setId(id);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo( mallApiFacadeService.getOrder(mallOrderApiParamDto ));
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Addresses",method = RequestMethod.GET)
    public BaseResultDto getAddresses(
    ) throws Exception {
        MallAddressApiParamDto mallAddressApiParamDto = new MallAddressApiParamDto();
        BaseResultDto resDto = new BaseResultDto();
        resDto.setQueryResult(mallApiFacadeService.getAddressList(mallAddressApiParamDto ) );
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Addresses",method = RequestMethod.POST)
    public BaseResultDto newAddress(
            @RequestBody  MallAddressApiParamDto mallAddressApiParamDto
    ) throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        mallApiFacadeService.newAddress( mallAddressApiParamDto);
        //result.setResultInfo( mallApiFacadeService));
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Addresses/{id}",method = RequestMethod.GET)
    public BaseResultDto getAddress(
            @PathVariable Long id
    ) throws Exception {
        MallAddressApiParamDto mallAddressApiParamDto = new MallAddressApiParamDto();
        mallAddressApiParamDto.setId( id);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo( mallApiFacadeService.getAddress(mallAddressApiParamDto ));
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Addresses/{id}",method = RequestMethod.DELETE)
    public BaseResultDto deleteAddress(
            @PathVariable Long id
    ) throws Exception {
        MallAddressApiParamDto mallAddressApiParamDto = new MallAddressApiParamDto();
        mallAddressApiParamDto.setId( id);
        BaseResultDto resDto = new BaseResultDto();
        mallApiFacadeService.deleteAddress(mallAddressApiParamDto );
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Members/Addresses/{id}",method = RequestMethod.PUT)
    public BaseResultDto modifyAddress(
            @RequestBody  MallAddressApiParamDto mallAddressApiParamDto
    ) throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        mallApiFacadeService.modifyAddress( mallAddressApiParamDto);
        //result.setResultInfo( mallApiFacadeService));
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value = "/Order/Prepay",method = RequestMethod.POST)
    public BaseResultDto orderPrepay(@RequestBody MallOrderPrepayParamDto paramDto) throws Exception {

        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo( mallApiFacadeService.prepay(paramDto));
        resDto.setResultCode(0);
        return resDto;
    }




}
